package com.zzy.openrequest.controller;

import cn.hutool.json.JSONObject;
import com.zzy.openrequest.chatservice.ChatService;
import com.zzy.openrequest.dto.Message;
import com.zzy.openrequest.dto.Prompt;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController

public class OpenRequestController {


    @Resource
    private ChatService chatService;

    private final List<Message> chatHistoryList = new ArrayList<>();
    @PostConstruct
    public void init() {
        chatHistoryList.add(new Message("assistant","我是你的人工助手AI,有什么问题尽管向我提问。"));
    }

    @PostMapping("/request")
    public String request(@RequestParam("message") String message){

        chatHistoryList.add(new Message("user",message));
        Prompt prompt = new Prompt();
        prompt.setMessages(chatHistoryList);
        JSONObject chatResponse = chatService.call(prompt);
        return chatResponse.toString();



    }


}
